package _04_tx;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;

import java.io.UnsupportedEncodingException;

public class TxProducer {

    public static void main(String[] args) throws MQClientException, UnsupportedEncodingException {
        // 事务生产者
        TransactionMQProducer producer = new TransactionMQProducer("tx-producer");

        // 连接NameServer
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();

        // 指定事务的回调接口
        producer.setTransactionListener(new MyTransactionListener());

        TransactionSendResult result = producer.sendMessageInTransaction(
                new Message("tx-topic", "事务消息".getBytes("utf-8"))
                , "我的事务对象");

        System.out.println(result);

    }
}
